<?php
require "[system_path]system/framework.php";

$order=$_REQUEST['order'];
$orderField="item_order";                              // $_REQUEST['orderfield'];
$table=general::stringToArray("[php_property:table]"); // $_REQUEST['table'];
$arrayOrder=explode(",", $order);


//for ($n = 0; $n < sizeof($arrayOrder); $n++) {
$n=0;

$contentId = $_REQUEST['content_id'];

//$html="content id = $contentId - ";
$html="";


$contentData = db::getDataLine("content", "id='{$contentId}'");
$contentHtml = file::readTextFile($contentData['content_filename'], false);




foreach ($arrayOrder as $orderId)
    {

    //$sql = "UPDATE $table SET $orderField=$n WHERE id='$orderId'";
    //$sql = "UPDATE {$table[0]} SET $orderField=$n WHERE id='$orderId'";
    //db::sqlExec($sql);

    $orderId = str_ireplace("sortable_", "", $orderId);
    $html = $html . dom::getOutertext($orderId, $contentHtml);

    //$n++;

    
    }

    
    $content = new content();
    $content->contentId = $contentId;
    $content->text = $html;
    $content->createContent();
    
    
    
    //$contentHtml = dom::replaceInnerHtml("body", $html, $contentHtml);
     //$contentOrginal=dom::replaceInnerHtml("body", $this->text, $contentOrginal); 
    //file::createTextFile($contentData['content_filename'], $contentHtml, false);    
    
    //file::createTextFile("/tmp/content_order.txt", $html, true);
?>